package com.yyfax.pay.console.controller;

import javax.annotation.Resource;
import javax.validation.Valid;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.yyfax.framework.common.OpResponse;
import com.yyfax.pay.common.annotation.CheckSign;
import com.yyfax.pay.common.enums.OperationEnum;
import com.yyfax.pay.common.model.to.YYPayApiReq2;
import com.yyfax.pay.console.service.ResolveExpRecordService;
import com.yyfax.pay.vo.consloe.DealExpRsp;
import com.yyfax.pay.vo.consloe.QueryExpRecordReq;
import com.yyfax.pay.vo.consloe.ResolveExpRecordReq;

@RestController
public class ExceptionRecordController {
	@Resource
	private ResolveExpRecordService resolveExpRecordService;

	/**
	 * 查询异常记录
	 *
	 * @author wangjwy
	 * @date 2018/7/2 16:56
	 * @since 2.2.3
	 * @param req
	 * @return com.yyfax.framework.common.OpResponse
	 * @throws Exception
	 */
	@PostMapping("/api/console/query/exceptionRecords")
	@CheckSign
	public OpResponse queryExceptionRecordList(@Valid @RequestBody YYPayApiReq2<QueryExpRecordReq> req) {
		OpResponse response = OpResponse.success();
		response.setContent(resolveExpRecordService.listExceptionRecords(req.getParams()));
		return response;
	}

	/**
	 * 处理异常记录
	 *
	 * @author wangjwy
	 * @date 2018/7/2 16:57
	 * @since 2.2.3
	 * @param req
	 * @return com.yyfax.framework.common.OpResponse
	 * @throws Exception
	 */
	@PostMapping("/api/console/resolveExceptionRecords")
	@CheckSign
	public OpResponse resolveExceptionRecord(@Valid @RequestBody YYPayApiReq2<ResolveExpRecordReq> req) {
		OpResponse response = OpResponse.success();
		DealExpRsp content = resolveExpRecordService.resolve(req.getParams().getExpRecordIds(), OperationEnum.MAN_MADE.getValue());
		response.setContent(content);
		return response;
	}

	/**
	 * 关闭异常
	 *
	 * @author wangjwy
	 * @date 2018/7/2 16:57
	 * @since 2.2.3
	 * @param req
	 * @return com.yyfax.framework.common.OpResponse
	 * @throws Exception
	 */
	@PostMapping("/api/console/exceptionRecords/close")
	@CheckSign
	public OpResponse closeExceptionRecord(@Valid @RequestBody YYPayApiReq2<ResolveExpRecordReq> req) {
		OpResponse response = OpResponse.success();
		DealExpRsp content = resolveExpRecordService.close(req.getParams().getExpRecordIds(), OperationEnum.MAN_MADE.getValue());
		response.setContent(content);
		return response;
	}

}
